package Terminal.View;


import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.text.DateFormat;
import java.text.Format;
import java.text.SimpleDateFormat;

import java.util.Date;
import java.util.Locale;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JTextPane;



import Terminal.Entity.Dominio.ETimeRecord;



public class JPannelloModificaTimeRecordStart extends JPannelloDatiTimeRecord {
	private JLabel timerecordidlabel;
	private JLabel timerecordidtextlabel;
	private JLabel timerecorddatainiziolabel;
	private JTextField timerecorddatainiziotextlabel;
	private JLabel timerecorddatafinelabel;
	private JTextField timerecorddatafinetextlabel;
	private JLabel timerecorddescrizionelabel;
	private JTextPane timereocorddescrizionetext;
	
	private ETimeRecord timerecord;
	private int size_font_values=16;
	private int size_font_title=18;
	private JTextField timerecordtimeiniziotextlabel;
	private JTextField timerecordtimefinetextlabel;
	private static final long serialVersionUID = 1L;


	public JPannelloModificaTimeRecordStart(){
		super();
		createComponents();
	}
	
	private void createComponents() {
		this.setLayout(null);
		this.setBackground(Color.white);
		
		////////////////////////////////////PANNELLO DI DESCRIZIONE////////////////////////////////////
		
		
		
		timerecordidlabel = new JLabel("Identificatore:");
		timerecordidlabel.setLocation(20,20);//40,10);
		timerecordidlabel.setPreferredSize(new Dimension(200,50));//40));
		timerecordidlabel.setSize(timerecordidlabel.getPreferredSize());
		timerecordidlabel.setFont(new Font(timerecordidlabel.getFont().getFontName(), Font.PLAIN,size_font_title ));
		this.add(timerecordidlabel);
       
        
        
       
		timerecordidtextlabel= new JLabel("Assegnato automaticamente");
		
		timerecordidtextlabel.setLocation(220,27);//210,10);
		timerecordidtextlabel.setPreferredSize(new Dimension(200,35));//40));
		timerecordidtextlabel.setSize(timerecordidtextlabel.getPreferredSize());
		this.add(timerecordidtextlabel);
		
		timerecordidtextlabel.setFont(new Font(timerecordidtextlabel.getFont().getFontName(), Font.ITALIC, size_font_values));
		
		timerecorddescrizionelabel = new JLabel("Commento:");
		timerecorddescrizionelabel.setLocation(20,70);//40, 50);
		timerecorddescrizionelabel.setPreferredSize(new Dimension(200,50));// 40));
		timerecorddescrizionelabel.setSize(timerecorddescrizionelabel.getPreferredSize());
		timerecorddescrizionelabel.setFont(new Font(timerecorddescrizionelabel.getFont().getFontName(), Font.PLAIN,size_font_title ));
		this.add(timerecorddescrizionelabel);
        
        timereocorddescrizionetext = new JTextPane();
        timereocorddescrizionetext.setFont(new Font(timereocorddescrizionetext.getFont().getFontName(), Font.ITALIC,size_font_values ));
        
        JScrollPane scrollpanetesto = new JScrollPane(timereocorddescrizionetext);
       
        scrollpanetesto.setLocation(220,77);//210,timerecorddescrizionelabel.getLocation().y);
        scrollpanetesto.setPreferredSize(new Dimension(200,40));
        scrollpanetesto.setSize(scrollpanetesto.getPreferredSize());
		this.add(scrollpanetesto);

		
		timerecorddatainiziolabel = new JLabel("Data di inizio:");
		timerecorddatainiziolabel.setLocation(20,120);//40, 90);
		timerecorddatainiziolabel.setPreferredSize(new Dimension(200,40));
		timerecorddatainiziolabel.setSize(timerecorddatainiziolabel.getPreferredSize());
		timerecorddatainiziolabel.setFont(new Font(timerecorddatainiziolabel.getFont().getFontName(), Font.PLAIN,size_font_title ));
		this.add(timerecorddatainiziolabel);
        
		timerecorddatainiziotextlabel = new JTextField();
		timerecorddatainiziotextlabel.setEditable(false);
		timerecorddatainiziotextlabel.setLocation(220,127);//210,timerecorddatainiziolabel.getLocation().y);
		timerecorddatainiziotextlabel.setPreferredSize(new Dimension(200,35));//100,40));
		timerecorddatainiziotextlabel.setSize(timerecorddatainiziotextlabel.getPreferredSize());
		this.add(timerecorddatainiziotextlabel);
		timerecorddatainiziotextlabel.setFont(new Font(timerecorddatainiziotextlabel.getFont().getFontName(), Font.ITALIC,size_font_values));
		
		
		timerecordtimeiniziotextlabel = new JTextField();
		timerecordtimeiniziotextlabel.setEditable(false);
		timerecordtimeiniziotextlabel.setLocation(440,timerecorddatainiziotextlabel.getLocation().y);//320,timerecorddatainiziolabel.getLocation().y);
		timerecordtimeiniziotextlabel.setPreferredSize(new Dimension(85,35));//40));
		timerecordtimeiniziotextlabel.setSize(timerecordtimeiniziotextlabel.getPreferredSize());
		this.add(timerecordtimeiniziotextlabel);
		timerecordtimeiniziotextlabel.setFont(new Font(timerecordtimeiniziotextlabel.getFont().getFontName(), Font.ITALIC,size_font_values));
		
		
		
		timerecorddatafinelabel = new JLabel("Data di Fine:");
		timerecorddatafinelabel.setLocation(20,170);//40,130);
		timerecorddatafinelabel.setPreferredSize(new Dimension(200,50));//40));
		timerecorddatafinelabel.setSize(timerecorddatafinelabel.getPreferredSize());
		timerecorddatafinelabel.setFont(new Font(timerecorddatafinelabel.getFont().getFontName(), Font.PLAIN,size_font_title ));
		this.add(timerecorddatafinelabel);
		
        
        timerecorddatafinetextlabel = new JTextField();
        timerecorddatafinetextlabel.setEditable(false);
        timerecorddatafinetextlabel.setLocation(220,177);//210,timerecorddatafinelabel.getLocation().y);
		timerecorddatafinetextlabel.setPreferredSize(new Dimension(200,35));//100,40));
		timerecorddatafinetextlabel.setSize(timerecorddatafinetextlabel.getPreferredSize());
		this.add(timerecorddatafinetextlabel);
		
		timerecordtimefinetextlabel = new JTextField();
		timerecordtimefinetextlabel.setEditable(false);
		timerecordtimefinetextlabel.setLocation(440,timerecorddatafinetextlabel.getLocation().y);//320,timerecorddatafinelabel.getLocation().y);
		timerecordtimefinetextlabel.setPreferredSize(new Dimension(85,35));//40));
		timerecordtimefinetextlabel.setSize(timerecordtimefinetextlabel.getPreferredSize());
		this.add(timerecordtimefinetextlabel);
		timerecordtimefinetextlabel.setFont(new Font(timerecordtimefinetextlabel.getFont().getFontName(), Font.ITALIC,size_font_values));
	
		
		timerecorddatafinetextlabel.setFont(new Font(timerecorddatafinetextlabel.getFont().getFontName(), Font.ITALIC,size_font_values));
		
	
		//setBounds(370, 80, 700,350);
		setBounds(400,231,900,350);
		setBorder(BorderFactory.createLineBorder(Color.GRAY));
		
		if(this.timerecord!=null)visualizzaElemento(this.timerecord);
		
	}
	
	public void visualizzaElemento(ETimeRecord timerecord) {
		//this.timerecord =timerecord;
		Format dateformat= new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy",Locale.ENGLISH);
		Format dateformat2= new SimpleDateFormat("dd/MM/yyyy");
		Format timeformat = new SimpleDateFormat("HH:mm");
		
		try{timerecordidtextlabel.setText(timerecord.getId()+" ");} catch (Exception e) {timerecordidtextlabel.setText("  ");		}
		try{
			if(timerecord.getDataInizio()!=null) 	
			{
				Date datetemp= timerecord.getDataInizio();
				timerecorddatainiziotextlabel.setText(dateformat2.format(datetemp));
				timerecordtimeiniziotextlabel.setText(timeformat.format(datetemp));
				
			}
		}
		catch (Exception e) 
		{
			timerecorddatainiziotextlabel.setText(" ");
			timerecordtimeiniziotextlabel.setText(" ");
			}
		
		try{
			if(timerecord.getDataFine()!=null)
				{
					Date datetemp= timerecord.getDataFine();
					timerecorddatafinetextlabel.setText(dateformat2.format(datetemp));
					timerecordtimefinetextlabel.setText(timeformat.format(datetemp));
					
			}
		}
		catch (Exception e) 
		{
			timerecorddatafinetextlabel.setText(" ");
			timerecordtimefinetextlabel.setText(" ");
			}
		try{if(timerecord.getTesto()!=null) timereocorddescrizionetext.setText(timerecord.getTesto());else timereocorddescrizionetext.setText(" ");} catch (Exception e) { timereocorddescrizionetext.setText(" ");}
		
	
	}

	
	
	public ETimeRecord catturaElemento(){
		DateFormat dataformat= new SimpleDateFormat("dd/MM/yyyy HH:mm");
		ETimeRecord s = new ETimeRecord();
		Date d = new Date();
		try{d=dataformat.parse(timerecorddatainiziotextlabel.getText());  }catch (Exception e) {}
		s.setDataInizio(d);
		System.out.print(d);
		try{d=dataformat.parse(timerecorddatafinetextlabel.getText());}catch (Exception e) {	}
		s.setDataFine(d);
		try{ s.setTesto(timereocorddescrizionetext.getText());} catch (Exception e){}
				
		return s;
	}
		
	
}